package subStringCount;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class SubstringCount {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String input = scanner.nextLine();
        scanner.close();


        for (int i = 1; i <= input.length(); i++) {
            Map<String, Integer> substringCounts = new HashMap<>();
            int start = 0;
            while (start <= input.length() - i) {

                String substring = input.substring(start, start + i);

                substringCounts.put(substring, substringCounts.getOrDefault(substring, 0) + 1);
                start++;
            }


            for (Map.Entry<String, Integer> entry : substringCounts.entrySet()) {
                System.out.println("长度为" + i + "的字串 '" + entry.getKey() + "' 出现了 " + entry.getValue() + " 次");
            }
        }
    }
}
